using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace Meta
{
	public class Inspector : Form {
		protected InspectorBox realInspector;
		public TopLevel threadBeingDebugged;
		bool showCurrentExpression=false;
		public static Size defaultSize = new Size(416, 392);

		protected System.Windows.Forms.MainMenu mainMenu;
		private System.Windows.Forms.MenuItem inspectMenu;
		private System.Windows.Forms.MenuItem backMenuItem;
		private System.Windows.Forms.MenuItem debugMenu;
		private System.Windows.Forms.MenuItem stepMenuItem;
		private System.Windows.Forms.MenuItem continueMenuItem;
		private System.Windows.Forms.MenuItem breakpointMenuItem;

		public static bool showDetail = false;
		private System.Windows.Forms.Button backButton;
		private System.Windows.Forms.Button explainButton;
		private System.Windows.Forms.Button forwardButton;
		private System.Windows.Forms.Button invisibleCloseButton;
		private System.Windows.Forms.MenuItem showCurrentExpressionMenuItem;
		private System.Windows.Forms.MenuItem editDefinitionMenuItem;
		private System.Windows.Forms.MenuItem advancedMenu;
		private System.Windows.Forms.MenuItem clearAllBreakpointsMenuItem;
		private System.Windows.Forms.MenuItem traceMenuItem;
		private System.Windows.Forms.MenuItem clearAllTracesMenuItem;
		private System.Windows.Forms.TextBox searchBox;
		private System.Windows.Forms.MenuItem DumpMenuItem;
		private System.Windows.Forms.MenuItem stepOverMenuItem;
		private System.ComponentModel.IContainer components = null;

		public bool IsDebugger {
			get {
				return threadBeingDebugged != null && threadBeingDebugged.thread!=null && threadBeingDebugged.thread.IsAlive;
			}
		}

		public static void Inspect (object obj) {
			Meta.TopLevel.LaunchForm(typeof(Inspector), new Object[] { obj });
		}

		public static void Debug() {
			// This is called from an Eval thread, not from GUI context.
			EvalStack.CurrentThreadEvalStack.InvalidateRenderCache();
			if (Meta.TopLevel.standAloneMode)
				new Inspector(EvalStack.CurrentThreadEvalStack, Meta.TopLevel.CurrentThreadTopLevel).ShowDialog();
			else
				Meta.TopLevel.LaunchForm(typeof(Inspector), new Object[2] { EvalStack.CurrentThreadEvalStack, Meta.TopLevel.CurrentThreadTopLevel} );
		}

		public Inspector(Object newObj) : this(newObj, null) {
		}

		public Inspector(Object newObj, Meta.TopLevel threadBeingDebugged) {
		    this.threadBeingDebugged = threadBeingDebugged;
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			new StaticFlagMenuItem(advancedMenu, "Show &All expressions in debugger", "EvalStack", "showAllExpressions");
			new StaticFlagMenuItem(advancedMenu, "Show &Detail", "Inspector", "showDetail");
			new StaticFlagMenuItem(advancedMenu, "Show &Current expression on breakpoint", "Inspector", "showExpressionOnBreak");
			
			this.Size = defaultSize;
			realInspector.Push(newObj);
			HandleCurrentObjectChanged(realInspector, newObj);

			if (threadBeingDebugged != null || newObj is EvalStack) {
				if (threadBeingDebugged!=null)
					threadBeingDebugged.debugger = this;
				showCurrentExpression=true;
			}
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing ) {
			if( disposing ) {
				if (components != null) {
					components.Dispose();
				}
				if (IsDebugger && threadBeingDebugged.thread.IsAlive) {
					threadBeingDebugged.Kill();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Inspector));
			this.realInspector = new Meta.InspectorBox();
			this.mainMenu = new System.Windows.Forms.MainMenu();
			this.inspectMenu = new System.Windows.Forms.MenuItem();
			this.backMenuItem = new System.Windows.Forms.MenuItem();
			this.editDefinitionMenuItem = new System.Windows.Forms.MenuItem();
			this.showCurrentExpressionMenuItem = new System.Windows.Forms.MenuItem();
			this.advancedMenu = new System.Windows.Forms.MenuItem();
			this.debugMenu = new System.Windows.Forms.MenuItem();
			this.continueMenuItem = new System.Windows.Forms.MenuItem();
			this.stepMenuItem = new System.Windows.Forms.MenuItem();
			this.breakpointMenuItem = new System.Windows.Forms.MenuItem();
			this.clearAllBreakpointsMenuItem = new System.Windows.Forms.MenuItem();
			this.traceMenuItem = new System.Windows.Forms.MenuItem();
			this.clearAllTracesMenuItem = new System.Windows.Forms.MenuItem();
			this.DumpMenuItem = new System.Windows.Forms.MenuItem();
			this.backButton = new System.Windows.Forms.Button();
			this.explainButton = new System.Windows.Forms.Button();
			this.forwardButton = new System.Windows.Forms.Button();
			this.invisibleCloseButton = new System.Windows.Forms.Button();
			this.searchBox = new System.Windows.Forms.TextBox();
			this.stepOverMenuItem = new System.Windows.Forms.MenuItem();
			this.SuspendLayout();
			// 
			// realInspector
			// 
			this.realInspector.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.realInspector.BackColor = System.Drawing.SystemColors.Control;
			this.realInspector.DisplayMember = "DisplayString";
			this.realInspector.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
			this.realInspector.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.realInspector.IntegralHeight = false;
			this.realInspector.ItemHeight = 16;
			this.realInspector.Location = new System.Drawing.Point(0, 32);
			this.realInspector.Name = "realInspector";
			this.realInspector.Size = new System.Drawing.Size(408, 304);
			this.realInspector.TabIndex = 0;
			this.realInspector.CurrentObjectChanged += new Meta.InspectorBox.CurrentObjectChangedHandler(this.HandleCurrentObjectChanged);
			// 
			// mainMenu
			// 
			this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.inspectMenu,
																					 this.advancedMenu,
																					 this.debugMenu});
			// 
			// inspectMenu
			// 
			this.inspectMenu.Index = 0;
			this.inspectMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						this.backMenuItem,
																						this.editDefinitionMenuItem,
																						this.showCurrentExpressionMenuItem});
			this.inspectMenu.Text = "&Inspect";
			this.inspectMenu.Popup += new System.EventHandler(this.MenuPop_Inspect);
			// 
			// backMenuItem
			// 
			this.backMenuItem.Index = 0;
			this.backMenuItem.Shortcut = System.Windows.Forms.Shortcut.AltBksp;
			this.backMenuItem.Text = "&Back";
			this.backMenuItem.Click += new System.EventHandler(this.MenuClick_Back);
			// 
			// editDefinitionMenuItem
			// 
			this.editDefinitionMenuItem.Index = 1;
			this.editDefinitionMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlD;
			this.editDefinitionMenuItem.Text = "&Edit definition";
			this.editDefinitionMenuItem.Click += new System.EventHandler(this.EditDefinition_Click);
			// 
			// showCurrentExpressionMenuItem
			// 
			this.showCurrentExpressionMenuItem.Index = 2;
			this.showCurrentExpressionMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlShiftD;
			this.showCurrentExpressionMenuItem.Text = "&Show current expression";
			this.showCurrentExpressionMenuItem.Click += new System.EventHandler(this.ShowCurrentExpressionMenuItem_Click);
			// 
			// advancedMenu
			// 
			this.advancedMenu.Index = 1;
			this.advancedMenu.Text = "&Advanced";
			// 
			// debugMenu
			// 
			this.debugMenu.Index = 2;
			this.debugMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.continueMenuItem,
																					  this.stepMenuItem,
																					  this.stepOverMenuItem,
																					  this.breakpointMenuItem,
																					  this.clearAllBreakpointsMenuItem,
																					  this.traceMenuItem,
																					  this.clearAllTracesMenuItem,
																					  this.DumpMenuItem});
			this.debugMenu.Text = "&Debug";
			this.debugMenu.Popup += new System.EventHandler(this.MenuPop_Debug);
			// 
			// continueMenuItem
			// 
			this.continueMenuItem.Index = 0;
			this.continueMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlE;
			this.continueMenuItem.Text = "Continue &Execution to completion";
			this.continueMenuItem.Click += new System.EventHandler(this.MenuClick_Continue);
			// 
			// stepMenuItem
			// 
			this.stepMenuItem.Index = 1;
			this.stepMenuItem.Shortcut = System.Windows.Forms.Shortcut.Ctrl1;
			this.stepMenuItem.Text = "Continue &1 Step";
			this.stepMenuItem.Click += new System.EventHandler(this.MenuClick_Step);
			// 
			// breakpointMenuItem
			// 
			this.breakpointMenuItem.Index = 3;
			this.breakpointMenuItem.Shortcut = System.Windows.Forms.Shortcut.ShiftDel;
			this.breakpointMenuItem.Text = "&Breakpoint";
			this.breakpointMenuItem.Click += new System.EventHandler(this.MenuClick_Breakpoint);
			// 
			// clearAllBreakpointsMenuItem
			// 
			this.clearAllBreakpointsMenuItem.Index = 4;
			this.clearAllBreakpointsMenuItem.Text = "Clear all breakpoints";
			this.clearAllBreakpointsMenuItem.Click += new System.EventHandler(this.clearAllBreakpointsMenuItem_Click);
			// 
			// traceMenuItem
			// 
			this.traceMenuItem.Index = 5;
			this.traceMenuItem.Text = "&Trace";
			this.traceMenuItem.Click += new System.EventHandler(this.MenuClick_Trace);
			// 
			// clearAllTracesMenuItem
			// 
			this.clearAllTracesMenuItem.Index = 6;
			this.clearAllTracesMenuItem.Text = "Clear all traces";
			this.clearAllTracesMenuItem.Click += new System.EventHandler(this.clearAllTracesMenuItem_Click);
			// 
			// DumpMenuItem
			// 
			this.DumpMenuItem.Index = 7;
			this.DumpMenuItem.Text = "Create &dump file";
			this.DumpMenuItem.Click += new System.EventHandler(this.DumpMenuItem_Click);
			// 
			// backButton
			// 
			this.backButton.Font = new System.Drawing.Font("Wingdings 3", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(2)));
			this.backButton.Location = new System.Drawing.Point(0, 0);
			this.backButton.Name = "backButton";
			this.backButton.Size = new System.Drawing.Size(40, 32);
			this.backButton.TabIndex = 1;
			this.backButton.Text = "t";
			this.backButton.Click += new System.EventHandler(this.MenuClick_Back);
			// 
			// explainButton
			// 
			this.explainButton.Font = new System.Drawing.Font("Frutiger Linotype", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.explainButton.Location = new System.Drawing.Point(40, 0);
			this.explainButton.Name = "explainButton";
			this.explainButton.Size = new System.Drawing.Size(72, 32);
			this.explainButton.TabIndex = 2;
			this.explainButton.Text = "[explain]";
			this.explainButton.Click += new System.EventHandler(this.explainButton_Click);
			// 
			// forwardButton
			// 
			this.forwardButton.Font = new System.Drawing.Font("Wingdings 3", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(2)));
			this.forwardButton.Location = new System.Drawing.Point(112, 0);
			this.forwardButton.Name = "forwardButton";
			this.forwardButton.Size = new System.Drawing.Size(40, 32);
			this.forwardButton.TabIndex = 3;
			this.forwardButton.Text = "u";
			this.forwardButton.Click += new System.EventHandler(this.forwardButton_Click);
			// 
			// invisibleCloseButton
			// 
			this.invisibleCloseButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.invisibleCloseButton.Location = new System.Drawing.Point(328, 8);
			this.invisibleCloseButton.Name = "invisibleCloseButton";
			this.invisibleCloseButton.TabIndex = 4;
			this.invisibleCloseButton.Text = "close";
			this.invisibleCloseButton.Visible = false;
			this.invisibleCloseButton.Click += new System.EventHandler(this.invisibleCloseButton_Click);
			// 
			// searchBox
			// 
			this.searchBox.Anchor = System.Windows.Forms.AnchorStyles.Right;
			this.searchBox.Location = new System.Drawing.Point(260, 4);
			this.searchBox.Name = "searchBox";
			this.searchBox.Size = new System.Drawing.Size(144, 23);
			this.searchBox.TabIndex = 5;
			this.searchBox.Text = "Search";
			this.searchBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.searchBox_KeyDown);
			this.searchBox.TextChanged += new System.EventHandler(this.searchBox_TextChanged);
			this.searchBox.Enter += new System.EventHandler(this.searchBox_Enter);
			// 
			// stepOverMenuItem
			// 
			this.stepOverMenuItem.Index = 2;
			this.stepOverMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlShift1;
			this.stepOverMenuItem.Text = "Continue through call";
			this.stepOverMenuItem.Click += new System.EventHandler(this.MenuClick_StepOver);
			// 
			// Inspector
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(7, 16);
			this.CancelButton = this.invisibleCloseButton;
			this.ClientSize = new System.Drawing.Size(408, 337);
			this.Controls.Add(this.searchBox);
			this.Controls.Add(this.invisibleCloseButton);
			this.Controls.Add(this.forwardButton);
			this.Controls.Add(this.explainButton);
			this.Controls.Add(this.backButton);
			this.Controls.Add(this.realInspector);
			this.Font = new System.Drawing.Font("Frutiger Linotype", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.HelpButton = true;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.mainMenu;
			this.Name = "Inspector";
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
			this.Text = "Inspector";
			this.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.Inspector_HelpRequested);
			this.ResumeLayout(false);

		}
		#endregion
		
		private delegate void StupidDelegateType(EvalStack s);

		public void ShowBreakpoint() {
			Invoke(new StupidDelegateType(ShowBreakpointInternal), new object[1] {EvalStack.CurrentThreadEvalStack});
		}

		private void ShowBreakpointInternal(EvalStack stack) {
			Cursor = Cursors.Arrow;
			stack.InvalidateRenderCache();

			realInspector.Restart(stack);
			MaybeShowCurrentExpression();
			Refresh();
		}

		protected override void OnLayout(LayoutEventArgs e) {
			realInspector.Size = new Size(ClientSize.Width, ClientSize.Height-realInspector.Location.Y);
		}

		protected override void OnResize(EventArgs e) {
			if (Visible)
				defaultSize = Size;
			base.OnResize(e);
		}

		private Expression FindableExpression(object o) {
			EvalStack s = o as EvalStack;
			EvalStack.CallFrame f = o as EvalStack.CallFrame;
			EvalStack.PseudoContinuation p = o as EvalStack.PseudoContinuation;

			if (s==null) {
				if (f==null) {
					if (p==null)
						return Expression.FindableExpression(o);
					else
						return Expression.FindableExpression(p.expression);
				} else
					return Expression.FindableExpression(f.procedure);
			} else {
				// It's an EvalStack.
				return s.FindableExpression();
			}
		}

		private void MenuPop_Inspect(object sender, System.EventArgs ea) {
			object current = realInspector.CurrentObject;
			Expression e = FindableExpression(current);
			editDefinitionMenuItem.Enabled = e!=null && e.definedIn!=null;
			editDefinitionMenuItem.Text = editDefinitionMenuItem.Enabled?("Find &Definition of "+e.definedIn):"Find &Definition";
			showCurrentExpressionMenuItem.Enabled = e!=null;
			backMenuItem.Enabled = realInspector.CanPop;
		}

		private void EditDefinition_Click(object sender, EventArgs ea) {
			Meta.TopLevel.gui.EditSource(FindableExpression(realInspector.CurrentObject), false, true);
		}

		private void MenuClick_Close(object sender, System.EventArgs e) {
			Close();
		}

		private void MenuClick_Back(object sender, System.EventArgs e) {
			realInspector.Pop();
		}

		private void MenuPop_Debug(object sender, System.EventArgs e) {
			bool canDebug = IsDebugger;
			object tos = realInspector.CurrentObject;
			bool canBreakpoint = tos is Expression || tos is Procedure;
			bool canTrace = tos is Procedure;

			stepMenuItem.Enabled = canDebug;
			stepOverMenuItem.Enabled = canDebug;
			continueMenuItem.Enabled = canDebug;
			breakpointMenuItem.Enabled = canBreakpoint;

			if (canBreakpoint)
				breakpointMenuItem.Checked = (tos is Expression)?((Expression)tos).executionMode.Breakpoint:((Procedure)tos).Breakpointed;
			clearAllBreakpointsMenuItem.Enabled = Meta.TopLevel.BreakpointsSet;

			traceMenuItem.Enabled = canTrace;
			traceMenuItem.Checked = canTrace&&((Procedure)tos).Traced;
			clearAllTracesMenuItem.Enabled = Meta.TopLevel.TracesSet;
			DumpMenuItem.Enabled = tos is EvalStack;
		}

		private void HandleCurrentObjectChanged(object sender, object newObject) {
			debugMenu.Visible = IsDebugger || newObject is Expression || newObject is Procedure || newObject is EvalStack;
			backButton.Enabled = backMenuItem.Enabled = realInspector.CanGoBack;
			forwardButton.Enabled = realInspector.CanGoForward;
			explainButton.Enabled = realInspector.CanExplain;
			Refresh();
		}

		private void MenuClick_Breakpoint(object sender, EventArgs e) {
			object tos = realInspector.CurrentObject;
			if (tos is Procedure)
				Meta.TopLevel.ToggleBreakpoint(tos);
//			if (tos is Expression) {
//				Expression exp = (Expression)tos;
//			
//				exp.breakpoint = !exp.breakpoint;
//			} else {
//				Procedure p = (Procedure)tos;
//				p.breakpoint = ! p.breakpoint;
//			}
			Rerender();
		}

		private void MenuClick_Trace(object sender, EventArgs e) {
			Procedure tos = realInspector.CurrentObject as Procedure;
			if (tos!=null)
				Meta.TopLevel.ToggleTrace(tos);
			//			if (tos is Expression) {
			//				Expression exp = (Expression)tos;
			//			
			//				exp.breakpoint = !exp.breakpoint;
			//			} else {
			//				Procedure p = (Procedure)tos;
			//				p.breakpoint = ! p.breakpoint;
			//			}
			Rerender();
		}
		private void MenuClick_Step(object sender, EventArgs e) {
			Cursor = Cursors.WaitCursor;
			threadBeingDebugged.Step();
		}

		private void MenuClick_StepOver(object sender, EventArgs e) {
			Cursor = Cursors.WaitCursor;
			threadBeingDebugged.StepOver();
		}

		private void MenuClick_Continue(object sender, EventArgs e) {
			Cursor = Cursors.WaitCursor;
			threadBeingDebugged.Continue();
		}

		private void Rerender() {
			realInspector.UpdateRendering();
			Refresh();
		}

		protected override void OnPaint(PaintEventArgs e) {
			// We can't have the constructor pop the editor window
			// because our window hasn't been created yet, and so we'll
			// end up occluding it.  So it just sets a flag, which we check
			// once our window is popped up.
			if (showCurrentExpression) {
				MaybeShowCurrentExpression();
				showCurrentExpression=false;
			}
			base.OnPaint (e);
		}

		private void explainButton_Click(object sender, System.EventArgs e) {
			realInspector.Explain();
		}

		private void forwardButton_Click(object sender, System.EventArgs e) {
			realInspector.Forward();
		}

		private void invisibleCloseButton_Click(object sender, System.EventArgs e) {
			Close();
		}

		private void ShowCurrentExpressionMenuItem_Click(object sender, System.EventArgs e) {
			ShowCurrentExpression();
		}

		public static bool showExpressionOnBreak=true;
		void MaybeShowCurrentExpression() {
			if (showExpressionOnBreak)
				ShowCurrentExpression();
		}
		void ShowCurrentExpression() {
			Meta.TopLevel.gui.EditSource(FindableExpression(realInspector.CurrentObject), true, true);
		}

		private void clearAllBreakpointsMenuItem_Click(object sender, System.EventArgs e) {
			Meta.TopLevel.ClearAllBreakpoints();
		}

		private void clearAllTracesMenuItem_Click(object sender, System.EventArgs e) {
			Meta.TopLevel.ClearAllTraces();
		}

		int searchStart;
		private void searchBox_Enter(object sender, System.EventArgs e) {
			if (searchBox.Text=="Search")
				searchBox.Text = "";
			searchStart = Math.Max(0, Math.Min(0, realInspector.SelectedIndex));
		}

		void Search(string s) {
			if (s=="")
				return;
			for (int i=searchStart+1; i<realInspector.Items.Count; i++) {
				InspectorField f = realInspector.Items[i] as InspectorField;
				if (f!=null) {
					if (f.fieldName.IndexOf(s)>=0 || f.valueString.IndexOf(s)>=0) {
						realInspector.SelectedIndex = i;
						return;
					}
				}
			}
		}

		private void searchBox_TextChanged(object sender, System.EventArgs e) {
			Search(searchBox.Text);
		}

		private void searchBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) {
			if (e.KeyCode==Keys.Enter) {
				searchStart = realInspector.SelectedIndex;
				Search(searchBox.Text);
			}
		}

		public class Help : IInspectable {
			object[] text;
			string caption;

			public Help(string caption, params object[] text) {
				this.text = text;
				this.caption = caption;
			}

			string IInspectable.InspectorName() {
				return caption;
			}

			IList IInspectable.RenderForInspection() {
				InspectorField[] rendering = new InspectorField[text.Length];

				for (int i=0; i<rendering.Length; i++) {
					object item=text[i];
					if (item is String)
						rendering[i] = new InspectorField((string)item);
					else if (item is object[]) {
						object[] items = item as object[];
						if (items.Length==2 && items[0]!=null && items[0] is String && items[1]!=null && items[1] is String)
							rendering[i] = new InspectorField((string)items[0], null, (string)items[1], false);
					}
				}
				return (IList)rendering;
			}
		}
		static Help inspectorHelp = new Help("Inspector help",
			"This is the inspector.",
			"It allows you display and explore data objects in the system.",
			"Each line represents one field of the object being viewed.",
			"",
			new object[] {"Click a field:", "displays the data in the field"},
			new object[] {"Backspace:" ,"return to the previous data."},
			"",
			"Click the close box to remove this window.");
		private void Inspector_HelpRequested(object sender, System.Windows.Forms.HelpEventArgs hlpevent) {
			if (!(realInspector.CurrentObject is Help))
				realInspector.Push(inspectorHelp);
		}

		private void DumpMenuItem_Click(object sender, System.EventArgs e) {
			SaveFileDialog d = new SaveFileDialog();
			d.Filter = "Dump files (*.mdump)|*.mdump|All files (*.*)|*.*"  ;
			
			if(d.ShowDialog() == DialogResult.OK) {
				((EvalStack)realInspector.CurrentObject).DebugDump(d.FileName);
			}
			d.Dispose();
		}
	}
}
